
import os, ConfigParser

CONFIG = {}
c = ConfigParser.ConfigParser()
c.read('../../config.ini')
CONFIG = c.defaults()

XUL_SDK = CONFIG['xulrunner_sdk']
GPP_OPTIONS = '-I%s/include -I%s/include/mozilla -I%s/include/nspr -I%s -O0 -g3 -Wall -c -fmessage-length=0 --std=c++0x -fPIC -g' % (XUL_SDK, XUL_SDK, XUL_SDK, CONFIG['python_inc'])
LINK_OPTIONS = '-L%s/sdk/lib -lnspr4 -lxpcom -lxpcomglue_s -lmozalloc -ldl -lpython2.7 -shared -Xlinker -export-dynamic' % XUL_SDK

SOURCE_PATH = '../../src/main/cpp'
OUT_PATH = '../../output'
SOURCE = ['main', 
	'MainThreadMessagePipe', 
	'MessageTask', 
	'nsMessagePipe', 
	'PythonMessageReceiver', 
	'utils', 
	'XulModule', 'platform/linux']



def compile_cpp():
	for f in SOURCE:
		src_file = os.path.join(SOURCE_PATH, f)
		cmd = 'g++ %s.cpp %s -o %s/obj/%s.o' % (src_file, GPP_OPTIONS, OUT_PATH, f)
		os.system(cmd)
	pass

def link():
	cmd = 'gcc %s/obj/*.o %s/obj/platform/*.o %s -o %s/pyxul.so' % (OUT_PATH, OUT_PATH, LINK_OPTIONS, OUT_PATH)
	os.system(cmd)
	pass


compile_cpp()
link()
